package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

    private Button btn;

    @SuppressLint("WrongConstant")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=findViewById(R.id.btn);
        SharedPreferences preferences = getSharedPreferences("count",MODE_PRIVATE);
        //读取SharedPreferences里的count数据
        int count = preferences.getInt("count" , 0);
        //显示程序以前使用的次数
        Toast.makeText(this , "程序以前被使用了" + count + "次。", 10000).show();
        SharedPreferences.Editor editor = preferences.edit();
        //存入数据
        editor.putInt("count" , ++count);
        //提交修改
        editor.commit();

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,DBTest.class);
                startActivity(intent);
            }
        });
    }
}
